<?php

namespace App\Services;

use App\Lib\Util\ErrorCode;
use App\Lib\Util\ErrorMessage;

class ResponseService extends BaseService
{
    static public function success($data)
    {
        return [
            'code' => ErrorCode::SUCCESS_CODE,
            'message' => ErrorMessage::getMessage(Errorcode::SUCCESS_CODE),
            'data' => $data,
        ];
    }

    static public function exception(\Throwable $exception)
    {
        $message = ($exception->getMessage() != '') ?
            $exception->getMessage() :
            ErrorMessage::getMessage($exception->getCode());

        return [
            'code' => $exception->getCode(),
            'message' => $message,
        ];
    }
}
